package com.hashset;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectionsTest {
    public static void main(String[] args) {
        List<String> list = new ArrayList();
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
/*        Collections.shuffle(list);   // 将集合打乱
        System.out.println(list);*/

/*        Collections.reverse(list);   // 将集合反转
        System.out.println(list);*/

/*        Collections.addAll(list,"xiaohuang","xiaoming");   //添加
        System.out.println(list);*/

        Collections.sort(list);
        System.out.println(list);  //按照大小来排（从小到大）， 字母按照字母的首字母来排

        List<Student> list1 = new ArrayList();
        list1.add(new Student("zhangsan",10));
        list1.add(new Student("lisi",10));
        list1.add(new Student("xiaohong",11));
        Collections.sort(list1, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getAge().equals(o2.getAge())) {
                    return o1.getName().length() - o2.getName().length();
                }
                return o1.getAge() - o2.getAge();
            }
        });
        System.out.println(list1);


    }
}
